

/*
 * FHM JS v2015
 * Copyright 2015 FOR HIM MAGAZINE, All rights reserved.
 * http://www.enrz.com
 * 
 * Author: MichaeLee IT
 * Updated: Tue Mar 30 09:40 2015
 * http://www.michaelee.com
 */


$(document).ready(function() {
    //Show and hide submenu
    $("ul#globalnav li").hover( //Globalnav
        function() {
            if ($(window).width() > 640) {
                $(this).addClass("cur");
                $('ul:first',this).slideDown(300);
            }
        },
        function() {
            if ($(this).hasClass('active') && $(window).width() > 640) {
                $(this).addClass("cur");
                $('ul:first',this).slideUp(200);
            } else if ($(window).width() < 640) {
                $('ul:first',this).css("display","block");
            } else {
                $(this).removeClass("cur");
                $('ul:first',this).slideUp(200);
            }
        }
    );
    
    $("ul.gf-totop li").hover( //WC Barcode
        function() {
            $('div:first',this).fadeIn(300);
        },
        function(){
            $('div:first',this).fadeOut(200);
        }
    );
  
    //Show and hide promos
    $(".gallery-box").hover(
        function() {
            $(this).children(".gb-mask").animate({opacity: 0.5}, "");
            $(this).children(".gb-contbox").animate({bottom: 30}, "");
        },
        function() {
            $(this).children(".gb-mask").animate({opacity: 0}, "");
            $(this).children(".gb-contbox").animate({bottom: -40}, "");
        }
    );
    
    //Show and hide globalnav
    $(".mn-icon-drawer").click(
        function() {
            //$(".searchbox-mobile").slideUp();
            event.stopPropagation();
            $("ul#globalnav").css("height", $(window).height()-44);
            $("ul#globalnav, .quicknav-mobile").animate({left: 0}, "");
        }
    );
    $("html").not("ul#globalnav").click(function(){
        $("ul#globalnav, .quicknav-mobile").animate({left: -200}, "");
        $("ul#globalnav").animate({height: "auto"}, "");
    })
    $(".btn-icon-close").click(
        function() {
             $("ul#globalnav, .quicknav-mobile").animate({left: -200}, "");
             $("ul#globalnav").animate({height: "auto"}, "");
        }
    );
    //Show and hide searchbox
    /*$(".mn-icon-search").click(
        function() {
            $(".globalnav").slideUp();
            $(".searchbox-mobile").slideToggle();
        }
    );*/
    
    //Show & hide totop btn
	/*ScrollToTop button*/
    $(function() {
        $(window).scroll(function() {
            if ($(this).width() < 640 && $(this).scrollTop() > 0) {
                $("#globalheader").css({"position":"fixed","top":"0"});
            } else if($(this).width() > 640 && $(this).scrollTop() > 45) {
                $("#globalheader").css({"position":"fixed","top":"-46px"});
				$("ul.gf-totop").fadeIn();
			 } else {
                $("#globalheader").css({"position":"absolute","top":"0"});
			 }
            if ($(this).scrollTop() > 920) {
                $("#hot").css({"position":"fixed","top":"124px"});
			 } else {
                $("#hot").css({"position":"relative","top":"0"});
			 }
            if ($(this).scrollTop() == 0) {
                $("ul.gf-totop").fadeOut();
                $("#totopbtn-toggle").removeClass("totopbtn-close");             
			 }
        });
    });
    $("#totopbtn-toggle").click(function() {
        if ($("ul.gf-totop").css("display") == "none") {
            $("ul.gf-totop").fadeIn();
            $("#totopbtn-toggle").addClass("totopbtn-close");
        }
        else {
            $("ul.gf-totop").fadeOut();
            $("#totopbtn-toggle").removeClass("totopbtn-close");
        }
    });
    
	$("ul.gf-totop li.top").click(function(){
		$("html,body").animate({scrollTop: $("body").offset().top}, 1000);
	});

});




//Show and hide content
function showHideCont(id) {
  if ($('#'+id).css("display")=="none") {
    $('#'+id).slideDown();
  }
  else {
    $('#'+id).slideUp();
  }
}

function is_mobile() {
    var regex_match = /(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|jigs browser|hiptop|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220)/i;
    var u = navigator.userAgent;
    if (null == u) {
        return true;
    }
    var result = regex_match.exec(u);

    if (null == result) {
        return false
    } else {
        return true
    }
}